package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Getter@Setter
public class Region extends BaseDomain{

    public static final int STATE_NORMAL = 0;
    public static final int STATE_HOT = 1;

    private String name;

    private Region parent;

    private int state;

    public Map toTreeViewMap(){
        HashMap<Object, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("text",name);
        map.put("lazyLoad",true);
        //判断是否是推荐状态
        if (state==STATE_HOT){
            map.put("tags",new String[]{"推荐"});
        }
        return map;
    }

    public String getJson(){
        HashMap<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("name",name);
        map.put("state",state);
        if (parent!=null){
            map.put("parentId",parent.getId());
            map.put("parentName",parent.getName());
        }
        return JSONUtil.toJSONString(map);
    }
}